/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package se.kth.lwr.jeat.core;

/**
 *
 * @author david
 *
 * The base class for most objects in JEAT that implements the logic for getting
 * and setting names and descriptions. It implements <code>Comparable<Described> 
 * </code>, to fit well with parts of the JAVA Collection API (such as SortedSet)
 * which is frequently used in JEAT.
 *
 * 
 * Från början hette denna klass GeneralCategory och var ämnad som basklass för Kategorier.
 * Klassen är dock mer generell än så och delar egenskaper med klassen DataSource. Jag
 * valde därför att döpa om den till Described.
 */

public abstract class Described implements Describable, Comparable<Described>{

    //Name field
    private String name;

    //Description field
    private String description;
    

    public Described(String name, String description) {
        if(name==null){
            throw new IllegalArgumentException("Undefined name");
        }else if(description==null){
            throw new IllegalArgumentException("Undefined description");
        }
        this.name = name;
        this.description = description;
    }

    /**
     *
     *
     * @return The name of this category
     */
    public final String getName() {
        return name;
    }

    /**
     *
     * @return The description of this category
     */

    public final String getDescription() {
        return description;
    }

    @Override
    public String toString() {
        return name;
    }
    
    /**
     * Compares this Describable to another Describable. Comparison is based on following properties
     * and performed in the following order:
     * 
     * <ol>
     * <li> Class name</li>
     * <li> name of DataSource</li>
     * <li> description of DataSource</li>
     * </ol>
     */

    @Override
    public int compareTo(Described o) {
        //ensure consistance with equals
        if(this.equals(o)){
            return 0;
        }
        //first try sort on classes
        int val=this.getClass().getName().compareTo(o.getClass().getName());
        if(val!=0){
            return val;
        }
        
        //second try sort on name
        val=getName().compareTo(o.getName());
        if(val!=0){
            return val;
        }
        //last try sort on description
        val=getDescription().compareTo(o.getDescription());
        return val;
        
    }



}
